package leetcode.tree;

public class Lc1448 {


    int ans = 0;
    public int goodNodes(TreeNode root) {

        getAns(root, Integer.MIN_VALUE);
        return ans;
    }

    private void getAns(TreeNode node, int maxVal) {
        if (node == null) return;
        if (node.val >= maxVal) {
            ans++;
            maxVal = node.val;
        }
        getAns(node.left, maxVal);
        getAns(node.right, maxVal);
    }

}
